﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Data.Entity;
using com.codeplex.eatoutadvocate.DAL;
namespace com.codeplex.eatoutadvocate.BL
{   
    /// <summary>
    /// Driver for the Data Layer
    /// </summary>
    public class DataLogic
    {
        DataConnection daConnection;                //Data connection to Data Access Layer
        /// <summary>
        /// Constructor
        /// </summary>
        public DataLogic()
        {
            string conn = ConfigurationManager.ConnectionStrings["EatOutAdvocateData"].ConnectionString;
            daConnection = new DataConnection(conn);
        }

        /// <summary>
        /// Creates hash for users
        /// </summary>
        /// <param name="password">User identifier: Password, access token, etc.</param>
        /// <returns>Hash Code</returns>
        public string CreateHash(string password)
        {
            byte[] bytes = Encoding.Unicode.GetBytes(password);
            byte[] inArray = HashAlgorithm.Create("SHA1").ComputeHash(bytes);
            string passwordHash = Convert.ToBase64String(inArray);

            return passwordHash;
        }

        /// <summary>
        /// Calls GetRestaurants from the Data Layer
        /// </summary>
        /// <returns>List of all restaurants</returns>
        public List<Restaurant> GetRestaurants()
        {
            return daConnection.GetRestaurants();
        }

        /// <summary>
        /// Calls Store from the Data Layer
        /// </summary>
        /// <param name="eatout">EatOut object</param>
        /// <param name="userID">User ID</param>
        public void Store(int userID, Engine.EatOut eatout)
        {
            daConnection.Store(userID,eatout);
        }
    }
}
